package com.hdy.login.action;

import org.springframework.beans.factory.InitializingBean;

import com.hdy.framework.spring.entity.SpringContainer;
import com.hdy.login.dto.UserDto;
import com.hdy.login.entity.User;
import com.hdy.login.service.LoginService;
import com.opensymphony.xwork2.ActionSupport;

/*
	by 何栋宇
	2012-12-2
	/ssh/login/in.action
 */
//http://127.0.0.1/ssh/login/in.action
public class LoginAction extends ActionSupport implements InitializingBean{

	private static final long serialVersionUID = 4291032122107394291L;
	private LoginService loginService;
	private String userName;
	public String execute(){
		System.out.println("hello");
		
		
		
		return SUCCESS;
	}
	public String toRegist(){
		return "regist";//regist.jsp
	}
	public String regist(){
		//直接调用SpringContainer也可以解决
//		LoginService lg=SpringContainer.getAppCtx().getBean("loginService", LoginService.class);
	//方式二
		LoginService lg = SpringContainer.getBean("loginService", LoginService.class);
	
		UserDto dto = new UserDto();
		dto.setName(userName);
		loginService.saveUser(dto);
		lg.saveUser(dto);
		//方式三
		User user = this.loginService.saveDto(dto.getId(),dto, User.class);
		System.out.println(user.getId());
		return "registSuc";//registSuc.jsp
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("spring初始化LoginAction加载成功");
	}

	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
}
